package ai.esc.speedy.common.valueobject;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Lob;

/**
 * 扩展字段
 * <p>
 * JSON字符串形式存储
 *
 * @author 周广明
 * @version v1 2019/12/20 1:12
 */
@Getter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor

@Embeddable
public class Extend {

    @Lob
    @Column(name = "extend_data")
    private String extendData;

    @JsonIgnore
    public JSONObject getExtendJsonData() {
        if (StrUtil.isBlank(extendData)) {
            throw new RuntimeException("extendData is null!");
        }
        return JSONObject.parseObject(extendData);
    }
}
